﻿using SocialCee.EDM;
using SocialCee.WebApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace SocialCee.WebApi.Controllers
{
    public class PostsController : ApiController
    {
        public List<Models.Post> Get()
        {
            return Get(false);
        }
        // GET api/posts
        public List<Models.Post> Get([FromUri]bool p)
        {
            var data = DAL.Posts.GetPosts(p);

            var dataPrepared = data.Select(d => new Models.Post
            {
                ID = d.ID,
                Date = d.Date,
                Text = d.Post,
                Cmnts = p ? d.SocialNetworkPostComments.Select(c => new Cmnt { ID = c.ID, Date = c.Date, Text = c.Comment }).ToList() : null
            }).ToList();
            return dataPrepared;
        }
    }
}
